import React from 'react';
import styles from './index.less';
import { Table, Button, Tooltip } from 'antd';
import { tableLocale } from '@/tool/components/PageEmpty';
import moment from 'moment';
import PropTypes from 'prop-types';

import { TRAlert, TRMessage } from '#/components';
import { CloseCircleFilled } from '#/utils/antdIcons';
import { isTRArray } from '#/utils/attribute';

import { RegionId } from '#/utils/contacts.js';
import { iconLock } from '@/assets/icon';

import {
  onTabCellCheckPress,
  onTabCheckAll,
  onTabCheckJS,
  onTabLockPress,
  onTabElectricNumber,
  onTabIncomeNumber,
  onTabZHNumber,
} from './Additions';
import { TRInputMinus, TRInputPlus } from './TRInput';
import { TRMonitorMinus, TRRatioMinus, TRMonitorPlus, TRRatioPlus, TRCheck } from './Toolbar';
import { onCreatData, onCreatColumns, overMaxMessage, precisionReg, point } from './Helper';

class TRTable extends React.Component {
  static defaultProps = {
    list: [],
    isLoading: false,
    type: 'contract',
    isEdit: true, //是否编辑
    isLook: false,
    hasEdit: true,
    isChangeZH: false, //改变综合值col
    hasEditButton: false,
    buttons: [],
    onDataChange: () => {},
    rowClick: false,
    redList: [],
    onRowClick: () => {},
    plusOrMinus: 'minus', // 调节数值和调节比例  是否存在负数
    precision: 3, //输入框小数点精度，默认小数点后3位
  };
  __isDataChange__ = false; //判断表格里数据是否改变
  __LockLen__ = 0; //可编辑内容的长度
  __RowCheckKey__ = ''; //行选择框key值
  constructor(props) {
    super(props);
    const { list, type, precision } = this.props;
    if (list.length > 0) {
      const arr = list[0];
      this.__LockLen__ = arr.list ? arr.list.length : 0;
    }
    const columns = onCreatColumns(
      list,
      type,
      this._column.bind(this),
      this._TableCol.bind(this),
      precision,
    );
    this.__RowCheckKey__ = columns.length > 0 ? columns[0].key : '';
    this.state = {
      tableColumns: columns,
      isEdit: this.props.isEdit,
      isCheckAll: false,
      isLockAll: true,
      dataList: onCreatData(list, type, precision),
      orginList: JSON.parse(JSON.stringify(onCreatData(list, type, precision))),
      plusOrMinus: this.props.plusOrMinus,

      // powerAndelectricId stationId sourceId forecastStart this.props.selectStationId
    };
  }
  //重新渲染表格数据
  onRehData(array) {
    this.setState({
      dataList: onCreatData(array, this.props.type, this.props.precision),
      isCheckAll: false,
      orginList: JSON.parse(
        JSON.stringify(onCreatData(array, this.props.type, this.props.precision)),
      ),
    });
  }
  onRefreshOneData(item) {
    const dataList = this.state.dataList;
    let array = dataList.map((y) => {
      if (item.contractId === y.contractName.contractId) {
        item.list.forEach((x) => {
          let keyVal = '';
          if (item.xType === 'timer') {
            keyVal = moment(Number(x.xAxis)).format('HH:mm');
            if (keyVal === '00:00') {
              keyVal = '24:00';
            }
          } else {
            keyVal = x.xAxis;
          }
          y[keyVal].value = x.value;
        });
        y.quantity.value = item.quantity;
        if (y.amount) {
          y.amount.value = item.amount;
        }
        if (y.income) {
          y.income.value = item.income;
        }
        return y;
      }
      return y;
    });
    this.setState({
      dataList: array,
    });
  }
  onRefreshData(array) {
    const dataList = this.state.dataList;
    let list = array.filter((item) => item.contractId === null);
    let lastArr = onCreatData(list, this.props.type, this.props.precision);
    let tem = dataList.filter((item) => item.contractName.contractId !== undefined);
    this.__isDataChange__ = false;
    this.setState({
      dataList: [].concat(tem, lastArr),
    });
  }
  static getDerivedStateFromProps(nextProps, prevState) {
    if (nextProps.list.length !== prevState.dataList.length) {
      return {
        isCheckAll: false,
        isLockAll: true,
        dataList: onCreatData(nextProps.list, nextProps.type, nextProps.precision),
      };
    }

    return null;
  }
  _column(messag, number, width) {
    let list = this.state ? this.state.dataList : [];
    let isEdit = this.state ? this.state.isEdit : false;
    let temp =
      list.length > 0
        ? list.filter((item) => {
            const sRow = item[messag];
            if (sRow == undefined) {
              return false;
            }
            return sRow.isCheck === true || sRow.rowLock === true;
          })
        : [];
    const isCheck = list.length === 0 ? false : temp.length === list.length;
    if (!isEdit) {
      return <span>{messag}</span>;
    }
    return (
      <div className={styles.rowcol} style={{ width: width }}>
        <div className={styles.space} style={{ marginRight: 6 }} />
        <TRCheck
          onChange={() => {
            this._onColumnChange(messag, isCheck);
          }}
          checked={isCheck}
        />
        <div style={{ flex: 1, textAlign: 'center', marginRight: 10 }}>{messag}</div>
      </div>
    );
  }
  _onCheckTableLock(array) {
    let list = array.filter((item) => {
      return (
        Object.values(item).filter((jitem) => {
          return jitem.isInput && jitem.isCheck && jitem.isLock === false;
        }).length > 0
      );
    });
    if (list.length === 0) {
      const checkarr = array.filter((item) => {
        return (
          Object.values(item).filter((jitem) => {
            return jitem.isInput && jitem.isCheck;
          }).length > 0
        );
      });
      if (checkarr.length === 0) {
        return true;
      }
    }
    return list.length > 0;
  }
  _onColumnChange(keyVal, isCheck) {
    if (this.props.selectTimeChange) {
      this.props.selectTimeChange(keyVal, isCheck);
    }

    let list = this.state.dataList.map((item) => {
      let joc = item[keyVal];
      item[keyVal] = { ...joc, isCheck: !isCheck };
      const number = Object.values(item).filter((kitem) => {
        return kitem.hasE === false || (kitem.x !== 0 && kitem.isCheck);
      }).length;
      const lockNum = Object.values(item).filter((kitem) => {
        return kitem.isInput && kitem.isLock;
      }).length;
      const fistSel = number == Object.values(item).length - 1;
      item[this.__RowCheckKey__] = {
        ...item[this.__RowCheckKey__],
        isCheck: fistSel,
        isLock: lockNum === this.__LockLen__,
      };
      return item;
    });
    this.setState({
      dataList: list,
      isCheckAll: onTabCheckAll(this.__RowCheckKey__, list),
      isLockAll: this._onCheckTableLock(list),
    });
  }
  _onAllChange(isCheck) {
    if (this.props.selectTimeChange) {
      this.props.selectTimeChange(undefined, isCheck, 'checkAll');
    }
    let list = this.state.dataList;
    list = list.map((item) => {
      var obj = {};
      Object.keys(item).forEach((keyVal) => {
        const joc = item[keyVal];
        obj[keyVal] = { ...joc, isCheck: !isCheck };
      });
      return obj;
    });
    this.setState({
      dataList: list,
      isCheckAll: !isCheck,
      isLockAll: this._onCheckTableLock(list),
    });
  }
  _onTableChange(keyVal, e) {
    if (this.props.selectTimeChange) {
      if (keyVal === this.__RowCheckKey__) {
        this.props.selectTimeChange(undefined, e.isCheck, 'checkAll');
      } else {
        this.props.selectTimeChange(keyVal, e.isCheck);
      }
    }
    let list = this.state.dataList;
    let rowData = onTabCellCheckPress(this.__RowCheckKey__, this.__LockLen__, list[e.y], keyVal, e);
    list = list.map((item, index) => {
      if (index === e.y) {
        return rowData;
      }
      return item;
    });
    this.setState({
      dataList: list,
      isLockAll: this._onCheckTableLock(list),
      isCheckAll: onTabCheckAll(this.__RowCheckKey__, list),
    });
  }
  _onLockPress(isLock) {
    let list = onTabLockPress(this.__RowCheckKey__, this.__LockLen__, this.state.dataList, isLock);
    this.setState({
      dataList: list,
      isLockAll: !isLock,
    });
    this.props.onDataChange && this.props.onDataChange(list);
  }
  _onBlur(event, isRatio) {
    if (event.length === 0) {
      return;
    }
    let value = Number(event);
    this._onChangeTbaleColData(parseFloat(value), isRatio);
    if (this.props.selectTimeChange) {
      this.props.selectTimeChange(undefined, true, 'blur');
    }
  }
  _onChangeTbaleColData(value, isRatio) {
    const { dataList } = this.state;
    const { maxCapacity, powerAndelectricId, precision, type, isChangeZH } = this.props;
    let overMaxCapacityArr =
      [...dataList]
        .map((item) => {
          let keys = Object.keys(item).filter((key) => {
            let joc = item[key];
            let itemValue;
            if (joc.isInput && joc.isCheck && !joc.isLock && !joc.rowLock) {
              itemValue = isRatio ? (joc.value * (value / 100)).toFixed(precision) : value;
              itemValue = point(Number(itemValue), precision);
              if (itemValue > maxCapacity) {
                return joc;
              }
            }
          });
          return keys;
        })
        .flat() || [];
    if (maxCapacity && overMaxCapacityArr.length > 0) {
      this.messageInfo(maxCapacity, overMaxCapacityArr, powerAndelectricId);
    }
    let list = [...dataList].map((item) => {
      let obj = {};
      Object.keys(item).forEach((keyVal) => {
        const joc = item[keyVal];
        let temp = {};
        if (joc.isInput && joc.isCheck && !joc.isLock && !joc.rowLock) {
          temp.value = isRatio ? (joc.value * (value / 100)).toFixed(precision) : value;
          temp.value = point(Number(temp.value), precision);
          // parseFloat(Number(temp.value).toFixed(precision));
          if (temp.value === 0.0) {
            temp.value = 0;
          }
          if (temp.value > maxCapacity) {
            temp.value = maxCapacity;
          }
        }
        obj[keyVal] = { ...joc, ...temp };
      });
      if (type === 'contract' || type === 'contractele') {
        obj.quantity.value = onTabElectricNumber(obj);
        if (obj.contractName.contractId) {
          if (obj.income) {
            obj.income.value = onTabIncomeNumber(obj);
          }
          if (obj.amount) {
            obj.amount.value = onTabIncomeNumber(obj);
          }
        }
      }
      if (type === 'decompose') {
        let reslt = Number(obj.quantity.value - onTabElectricNumber(obj)).toFixed(
          this.props.precision,
        );
        if (reslt === 0) {
          reslt = 0;
        }
        obj.offset.value = reslt;
      }
      return obj;
    });
    if (isChangeZH) {
      list = onTabZHNumber(list);
    }
    this.__isDataChange__ = true;
    this.props.onDataChange && this.props.onDataChange(list);
    this.setState({
      dataList: list,
    });
  }
  messageInfo(maxCapacity, overMaxCapacityArr, powerAndelectricId) {
    let message = (
      <div
        style={{ maxWidth: 600, wordWrap: 'break-word', wordBreak: 'break-all', display: 'flex' }}
      >
        <CloseCircleFilled twoToneColor="#f00" />
        {overMaxMessage(maxCapacity, overMaxCapacityArr, powerAndelectricId)}
      </div>
    );
    TRMessage.error(message);
  }
  async _onEditPress(isEdit) {
    let awr = { index: 1 };
    if (isEdit) {
      awr = await TRAlert.show('当前工作将不被保存，继续执行此操作？');
    }
    if (awr.index === 1) {
      const { list, type } = this.props;
      var obj = { dataList: onCreatData(list, type, this.props.precision) };
      if (this.props.isChangeZH) {
        obj.dataList = JSON.parse(JSON.stringify(this.state.orginList));
      }
      this.setState({
        isEdit: !isEdit,
        isCheckAll: false,
        isLockAll: true,
        ...obj,
      });
    }
  }
  /*
   *value=>输入框文本 Array
   *keyVal =>时间点
   *e=>当前单元格记录
   */
  _onTabBlur(value, keyVal, e, blurEvent) {
    const { dataList } = this.state;
    const { maxCapacity, precision } = this.props;
    let len = 0;
    if (isTRArray(value)) {
      len = value.length;
      let isNumberFlag = value.some((item) => Number.isNaN(Number(item ? item : '空格')));
      if (blurEvent && isNumberFlag) {
        TRMessage.error('粘贴内容应为数值,请检查后重试');
        return;
      }
    }
    //判断如果粘贴文本不是Number类型，不更新数据，并提示
    let overMaxCapacityArr = [];
    let list = [...dataList].map((item, index) => {
      if (index === e.y) {
        var obj = { ...item };
        let keys = Object.keys(obj);
        //时间段索引位置
        let valueIndex = keys.findIndex((value) => value == keyVal);
        let timerKeyArr = keys.slice(valueIndex, valueIndex + len);
        timerKeyArr.map((timeKey, index) => {
          let timeKeyValue = point(Number(value[index].replace(precisionReg, '$1')), precision);
          if (maxCapacity && maxCapacity < timeKeyValue) {
            overMaxCapacityArr.push(timeKey);
            timeKeyValue = maxCapacity;
          }
          //如果单元格锁定不做修改
          if (!obj[timeKey].isLock) {
            const xAxis = obj[timeKey].xAxis;
            obj[timeKey] = {
              ...e,
              xAxis,
              value: timeKeyValue,
            };
          }
        });
        if (this.props.type === 'contract' || this.props.type === 'contractele') {
          obj.quantity.value = onTabElectricNumber(obj);
          if (obj.contractName.contractId) {
            if (obj.income) {
              obj.income.value = onTabIncomeNumber(obj);
            }
            if (obj.amount) {
              obj.amount.value = onTabIncomeNumber(obj);
            }
          }
        }
        if (this.props.type === 'decompose') {
          let reslt = Number(obj.quantity.value - onTabElectricNumber(obj)).toFixed(
            this.props.precision,
          );
          if (reslt === 0) {
            reslt = 0;
          }
          obj.offset.value = reslt;
        }
        return obj;
      }
      return item;
    });
    if (this.props.isChangeZH) {
      list = onTabZHNumber(list);
    }
    this.__isDataChange__ = true;
    this.props.onDataChange && this.props.onDataChange(list);
    this.setState(
      {
        dataList: list,
      },
      () => {
        //目前 发电交易/功率预测调整模块添加判断
        if (this.props?.powerAndelectricId) {
          const { powerAndelectricId } = this.props;
          if (maxCapacity && overMaxCapacityArr.length > 0 && blurEvent) {
            this.messageInfo(maxCapacity, overMaxCapacityArr, powerAndelectricId);
          }
        }
      },
    );
    if (this.props.selectTimeChange) {
      this.props.selectTimeChange(undefined, true, 'blur');
    }
  }
  _onRowPress(contractId, index) {
    const { dataList } = this.state;
    const { list, onRowClick } = this.props;
    let dataObj = dataList[index] || {};
    let listObj = list[index] || {};
    var obj = { ...listObj };
    let arr = [];
    Object.values(dataObj).forEach((item) => {
      if (item.isInput) {
        arr.push({ value: item.value === '-' ? null : item.value, xAxis: item.xAxis });
      }
    });
    obj.list = arr;
    onRowClick && onRowClick(obj);
  }
  async _onSavePress() {
    if (this.props.isChangeZH) {
      let last = this.state.dataList[this.state.dataList.length - 1];
      if (Number(last.offset.value) !== 0) {
        TRAlert.warning('请先调节电量曲线，使综合电量偏差为0');
        return;
      }
      let allNum = 0;
      let list = this.state.dataList.map((item) => {
        let quantity = {
          ...item.quantity,
          value: (Number(item.quantity.value) - Number(item.offset.value)).toFixed(
            this.props.precision,
          ),
        };
        let offset = { ...item.offset, value: '0' };
        let obj = {};
        if (this.props.type === 'decompose') {
          if (item.income) {
            obj.income = {
              ...item.income,
              value: item.electrovalency
                ? onTabIncomeNumber({ ...item, quantity: quantity })
                : allNum.toFixed(this.props.precision),
            };
            if (item.electrovalency) {
              allNum += Number(obj.income.value);
            }
          }
          if (item.amount) {
            obj.amount = {
              ...item.amount,
              value: item.electrovalency
                ? onTabIncomeNumber({ ...item, quantity: quantity })
                : allNum.toFixed(this.props.precision),
            };
            if (item.electrovalency) {
              allNum += Number(obj.amount.value);
            }
          }
        }
        return { ...item, quantity: quantity, offset: offset, ...obj };
      });
      let againList = this.state.orginList.filter((item, index) => {
        let jitem = list[index];
        let temp = Object.keys(item).filter((vkey) => {
          return Number(jitem[vkey].value) !== Number(item[vkey].value);
        });
        return temp.length > 0;
      });
      this.setState({
        orginList: JSON.parse(JSON.stringify(list)),
        dataList: list,
        isEdit: false,
      });
      this.props.onSaveDataChange && this.props.onSaveDataChange(list, againList.length > 0);
    } else {
      let list = this.state.dataList.filter((item) => Number(item.offset.value) !== 0);
      if (list.length > 0) {
        TRAlert.warning('请先调节电量曲线，使综合电量偏差为0');
        return;
      }
      this.setState({
        isEdit: false,
      });
      this.props.onSaveDataChange && this.props.onSaveDataChange(this.state.dataList);
    }
  }
  onCheckJS() {
    return onTabCheckJS(this.state.dataList);
  }
  _TableCol(keyVal, record, index) {
    const { isEdit, plusOrMinus, dataList } = this.state;
    const { rowClick, redList, precision, regionIdType, inputTabRowStyle = {} } = this.props;
    const cellItem = record[keyVal] || { rowLock: true, value: '-' };
    let isLink = rowClick && keyVal === this.__RowCheckKey__ && cellItem.contractId !== undefined;
    let className = styles.tabrow;
    if (cellItem.style !== undefined) {
      className = `${styles.tabrow}  ${cellItem.style === 'left' ? styles.left : styles.right} `;
    }
    const isRed = redList.indexOf(index) >= 0;
    var style = {};
    if (cellItem.tstyle == true) {
      style.width = cellItem.width - 1;
    }
    if (Object.keys(inputTabRowStyle).length > 0) {
      style.justifyContent = 'flex-start';
    }
    // 如果是山东 合约名称不可点击
    if (regionIdType === RegionId.shanDong) {
      isLink = false;
    }

    if (!isEdit || cellItem.hasE === false || cellItem.rowLock || cellItem.cLock) {
      return (
        <Tooltip overlayClassName="overtoop" title={cellItem.value || ''}>
          <div className={className} style={style}>
            {isLink ? (
              <a
                className={styles.textinput}
                onClick={() => {
                  this._onRowPress(cellItem.contractId, index);
                }}
                style={
                  keyVal === 'offset' && !(Number(cellItem.value) === 0) ? { color: 'red' } : {}
                }
              >
                {cellItem.value || '-'}
              </a>
            ) : (
              <span
                className={`${styles.textinput} ${
                  isRed &&
                  (keyVal === 'income' ||
                    keyVal === 'electrovalency' ||
                    keyVal === 'quantity' ||
                    cellItem.isInput) &&
                  Number(cellItem.value) < 0
                    ? styles.textinput_red
                    : ''
                }`}
                style={
                  keyVal === 'offset' && !(Number(cellItem.value) === 0) ? { color: 'red' } : {}
                }
              >
                {cellItem.value !== null ? cellItem.value : '-'}
              </span>
            )}
          </div>
        </Tooltip>
      );
    }
    if (cellItem) {
      let { maxCapacity, inputStyle = {}, lockImgStyle = {} } = this.props;
      return (
        <Tooltip overlayClassName="overtoop" title={cellItem.value || ''}>
          <div className={className} style={style}>
            <TRCheck
              checked={cellItem.isCheck}
              onChange={() => {
                this._onTableChange(keyVal, cellItem);
              }}
            />
            {cellItem.isInput ? null : <div className={styles.space} />}
            {/* {cellItem.isInput ? <TRInput disabled={cellItem.isLock} text={cellItem.value || "0.000"} cellItem={cellItem} keyVal={keyVal} onChange={this._onTabBlur.bind(this)} /> : (isLink ? <a onClick={() => { this._onRowPress(cellItem.contractId, index) }} className={styles.textinput}>{cellItem.value || "-"}</a> : <span className={styles.textinput} >{cellItem.value || "-"}</span>)} */}
            {cellItem.isInput ? (
              plusOrMinus === 'minus' ? (
                <TRInputMinus
                  disabled={cellItem.isLock}
                  text={cellItem.value || '0'}
                  cellItem={cellItem}
                  keyVal={keyVal}
                  onChange={this._onTabBlur.bind(this)}
                  precision={precision}
                  inputStyle={inputStyle}
                  lockImgStyle={lockImgStyle}
                />
              ) : (
                <TRInputPlus
                  disabled={cellItem.isLock}
                  text={cellItem.value || '0'}
                  cellItem={cellItem}
                  keyVal={keyVal}
                  onChange={this._onTabBlur.bind(this)}
                  precision={precision}
                  maxCapacity={maxCapacity}
                  powerAndelectricId={this.props.powerAndelectricId}
                  dataList={dataList}
                />
              )
            ) : isLink ? (
              <a
                onClick={() => {
                  this._onRowPress(cellItem.contractId, index);
                }}
                className={`${styles.textinput} ${
                  this.__RowCheckKey__ === keyVal ? styles.fistinput : null
                } `}
              >
                {cellItem.value || '-'}
              </a>
            ) : (
              <span
                className={`${styles.textinput} ${
                  this.__RowCheckKey__ === keyVal ? styles.fistinput : null
                } `}
              >
                {cellItem.value || '-'}
              </span>
            )}
            {cellItem.isInput ? (
              cellItem.isLock ? (
                <img className={styles.lockimg} style={{ width: 10, height: 11 }} src={iconLock} />
              ) : (
                <div className={styles.lockimg} />
              )
            ) : (
              <div className={styles.lockimg} />
            )}
          </div>
        </Tooltip>
      );
    }
    return <div />;
  }
  setRowClassName = (record) => {
    if (this.__RowCheckKey__ === '') {
      return '';
    }
    if (this.props.isLook) {
      if (record[this.__RowCheckKey__].contractId === undefined) {
        return 'clickRowStyl';
      }
      return;
    }
    return record[this.__RowCheckKey__].rowLock ? 'clickRowStyl' : '';
  };

  render() {
    const {
      list,
      style,
      type,
      hasEdit,
      buttons,
      hasEditButton,
      isLoading,
      precision,
      isAllChecked = true,
      scroll = true,
    } = this.props;
    const { dataList, isCheckAll, isLockAll, isEdit, plusOrMinus } = this.state;
    const columns = onCreatColumns(
      list,
      type,
      this._column.bind(this),
      this._TableCol.bind(this),
      this.props.precision,
    );
    if (this.__RowCheckKey__ === '') {
      this.__RowCheckKey__ = columns.length > 0 ? columns[0].key : '';
    }
    let tableParams = {};
    if (scroll && dataList.length > 0) {
      tableParams.scroll = { x: 1300 };
    }
    return (
      <div className={styles.table_container} id={'table'} style={style}>
        {hasEdit && list.length > 0 ? (
          <div className={styles.options}>
            {isEdit && isAllChecked ? (
              <TRCheck
                onChange={() => {
                  this._onAllChange(isCheckAll);
                }}
                checked={isCheckAll}
              >
                全选
              </TRCheck>
            ) : null}
            {/* {isEdit ? <TRMonitor onBlur={(event) => { this._onBlur(event, false) }} />:null} */}
            {/* {isEdit ? <TRRatio onBlur={(event) => { this._onBlur(event, true) }} />: null} */}
            {isEdit ? (
              plusOrMinus === 'minus' ? (
                <TRMonitorMinus
                  isAllChecked={isAllChecked}
                  onBlur={(event) => {
                    this._onBlur(event, false);
                  }}
                  precision={precision}
                />
              ) : (
                <TRMonitorPlus
                  isAllChecked={isAllChecked}
                  onBlur={(event) => {
                    this._onBlur(event, false);
                  }}
                  precision={precision}
                />
              )
            ) : null}
            {isEdit ? (
              plusOrMinus === 'minus' ? (
                <TRRatioMinus
                  onBlur={(event) => {
                    this._onBlur(event, true);
                  }}
                  precision={precision}
                />
              ) : (
                <TRRatioPlus
                  onBlur={(event) => {
                    this._onBlur(event, true);
                  }}
                  precision={precision}
                />
              )
            ) : null}
            <div style={{ flex: 1 }} />
            {isEdit
              ? buttons.map((item) => {
                  return item.authority ? (
                    <Button
                      type={item.hasSave ? ' ' : ''}
                      className={item.hasSave ? '' : styles.savegray}
                      onClick={() => {
                        item.onClick && item.onClick(dataList);
                      }}
                      style={{ marginRight: 10, marginLeft: 6 }}
                    >
                      {item.title}
                    </Button>
                  ) : (
                    <Button
                      onClick={() => {
                        item.onClick && item.onClick(dataList);
                      }}
                      style={{ marginRight: 10, marginLeft: 6 }}
                    >
                      {item.title}
                    </Button>
                  );
                })
              : null}
            {isEdit ? <div className={styles.space} /> : null}
            {isEdit ? (
              <Button
                onClick={() => {
                  this._onLockPress(isLockAll);
                }}
                style={{ marginRight: hasEditButton ? 10 : 0 }}
              >
                {isLockAll ? '锁定' : '解锁'}
              </Button>
            ) : null}
            {hasEditButton && isEdit ? <div className={styles.space} /> : null}
            {hasEditButton && isEdit ? (
              <Button
                type="primary"
                onClick={() => {
                  this._onSavePress();
                }}
                style={{ marginRight: 10 }}
              >
                保存
              </Button>
            ) : null}
            {hasEditButton ? <div className={styles.space} /> : null}
            {hasEditButton ? (
              <Button
                onClick={() => {
                  this._onEditPress(isEdit);
                }}
              >
                {isEdit ? '取消' : '编辑'}
              </Button>
            ) : null}
          </div>
        ) : null}
        <Table
          bordered
          tableLayout={'fixed'}
          loading={isLoading}
          rowClassName={this.setRowClassName}
          className={styles.table_view}
          locale={tableLocale}
          filterMultiple={false}
          pagination={false}
          columns={columns}
          {...tableParams}
          dataSource={dataList}
        />
      </div>
    );
  }
}

TRTable.propTypes = {
  list: PropTypes.array,
  type: PropTypes.string,
  precision: PropTypes.number,
  isEdit: PropTypes.bool,
  plusOrMinus: PropTypes.string,
  selectTimeChange: PropTypes.func,
  scroll: PropTypes.bool,
  isAllChecked: PropTypes.bool,
  isLoading: PropTypes.bool,
  hasEditButton: PropTypes.bool,
  buttons: PropTypes.any,
  hasEdit: PropTypes.bool,
  style: PropTypes.any,
  isLook: PropTypes.bool,
  rowClick: PropTypes.bool,
  redList: PropTypes.array,
  powerAndelectricId: PropTypes.number,
  onDataChange: PropTypes.func,
  maxCapacity: PropTypes.number,
  inputStyle: PropTypes.node,
  lockImgStyle: PropTypes.node,
  regionIdType: PropTypes.string,
  inputTabRowStyle: PropTypes.node,
  isChangeZH: PropTypes.bool,
  onSaveDataChange: PropTypes.func,
  onRowClick: PropTypes.func,
};

export default TRTable;
